#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
	long long int a, b, p, ans = 1;
	scanf("%lld%lld%lld", &a, &b, &p);
	long long int ar = a, br = b;
	while (b > 0) {
		if (b & 1) {
			ans = ans * a % p;
		}
		a = a * a % p;
		b = b >> 1;
	}
	ans = ans % p;
	printf("%lld^%lld mod %lld=%lld", ar, br, p, ans);
	return 0;
}
